package com.wjf.birdfish.util;

import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.UUID;

import org.apache.log4j.Logger;


/*****
 * 读取需要同步交易库表名的配置文件的工具类
 * @author lzp
 *
 */
public class SynchronizedDbTablesUtil {
	
	private static Logger LOG = Logger.getLogger(SynchronizedDbTablesUtil.class
			.getName());
	
	private static List<String> tables = new ArrayList<String>();
	private static List<String> incrFreshTables = new ArrayList<String>();
	
	static {
		/*BufferedReader br = null;
		
		try {
			br = new BufferedReader(new InputStreamReader(SynchronizedDbTablesUtil.class.getResourceAsStream("/synchronizedDbTables.txt")));
			String table= null;
			do{
				
				table = br.readLine();
				if(table !=null){
					tables.add(table);
				}
			}while(table != null);
		} catch (Exception ex) {
			LOG.error("load file synchronizedDbTables.txt error." + ex.getMessage());
		} finally {
			try {
				if (br != null)
					br.close();
			} catch (IOException e) {
			}
		}*/
		
		try {
			ResourceBundle bundle = ResourceBundle.getBundle("synchronizedDbTables");
			Set<String> keys =  bundle.keySet();
			tables=new ArrayList<String>(keys);
			for (String key: keys) {
				String isFull=bundle.getString(key);
				if("Y".equals(isFull)){
					incrFreshTables.add(key);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			LOG.error("load file synchronizedDbTables.properties error." + e.getMessage());
		}
		LOG.debug("all SynchronizedDbTables:" + tables +"\n incrFreshTables:"+incrFreshTables);
	}

	public static List<String> getIncrFreshTables() {
		if(incrFreshTables.size() > 0){
			return incrFreshTables;
		}
		return null;
	}
	
	public static List<String> getSynchronizedDbTables() {
		if(tables.size() > 0){
			return tables;
		}
		return null;
	}
	public static void main(String[] args){
		System.out.println(getSynchronizedDbTables());
		System.out.println(getIncrFreshTables());
	}
}
